package com.jMEF.gmm;

import java.util.Vector;

public class ExpectationMaximization {
	
	private static int MAX_ITERATIONS = 30;

	public static MixtureModel initialize(Vector<PVector>[] clusters, ExponentialFamily EF) {
		// Mixture initialization with number Gaussian
		MixtureModel mm = new MixtureModel(clusters.length);
		mm.EF = EF;
		// Amount of points
		int nb = 0;
		for (int i = 0; i < clusters.length; i++)
			nb += clusters[i].size(); // No. vector in cluster
		// Loop on clusters
		for (int i = 0; i < clusters.length; i++) {
			// Weight
			mm.weight[i] = ((double) clusters[i].size()) / nb;
			// Expectation parameters
			Parameter param = EF.t(clusters[i].get(0)); // PVectorMatrix

			for (int j = 1; j < clusters[i].size(); j++)
				param = param.Plus(mm.EF.t((PVector) clusters[i].get(j)));

			param = param.Times(1.0d / clusters[i].size());
			
			//Converts expectation parameters to source parameters.
			mm.param[i] = mm.EF.Eta2Lambda(param); // PVectorMatrix
		}
		return mm;
	}
	public static MixtureModel run(PVector[] pointSet, MixtureModel fL) {
		
		return null;
	}
}
